package team.first.dataimport;

import cn.hutool.db.Db;
import cn.hutool.db.Entity;
import org.neo4j.driver.Result;
import org.neo4j.driver.Session;
import team.first.util.DriverUtil;

import java.sql.SQLException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import static org.neo4j.driver.Values.parameters;

/**
 * @Author: 然然然儿呐_
 * @Project_name: project
 * @Package_name: team.first
 * @Date: 2021/12/3 11:16
 * @Description:
 */
public class GenreImport {
    public static void genreImport() {
        Session session = DriverUtil.getNewSession();
        try {
            List<Entity> genreList = Db.use().query("select * from genre order by id");

            String addGenre = "CREATE (:Genre{id:$id, name:$name})";
            genreList.forEach(genre -> {
                Map<String, Object> params = new HashMap<>();
                params.put("id", genre.getInt("id"));
                params.put("name", genre.getStr("name"));
                session.run(addGenre, params);
            });
        } catch (SQLException e) {
            e.printStackTrace();
        }finally {
            DriverUtil.close(session);
        }

    }
}
